package com.nidu.demo.mail.executor.query;

import com.alibaba.cola.dto.MultiResponse;
import com.nidu.demo.mail.convertor.MailAccountConvertor;
import com.nidu.demo.mail.convertor.MailAccountCriteriaConvertor;
import com.nidu.demo.mail.dto.MailAccountCO;
import com.nidu.demo.mail.dto.MailAccountListQry;
import com.nidu.demo.mail.gateway.MailAccountGateway;
import com.nidu.demo.mail.model.MailAccount;
import com.nidu.demo.mail.model.MailAccountCriteria;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 邮件账号列表查询执行器
 *
 * @author auto
 */
@Component
@RequiredArgsConstructor
public class MailAccountListQryExe {

    private final MailAccountCriteriaConvertor criteriaConvertor;
    private final MailAccountGateway gateway;
    private final MailAccountConvertor convertor;

    public MultiResponse<MailAccountCO> execute(MailAccountListQry qry) {
        MailAccountCriteria criteria = criteriaConvertor.toDataObject(qry);
        List<MailAccount> templates = gateway.listByCondition(criteria);
        List<MailAccountCO> templateCOS = convertor.toClientObjects(templates);
        return MultiResponse.of(templateCOS);
    }
}
